﻿using Irony.Parsing;
using NMF.Languages.AnyText.ClassConstruction;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NMF.Languages.AnyText
{
    public class StringTypeTerminal : DataTypeTerminal<StringType>
    {
        public StringTypeTerminal(string name, StringType type)
            : base(name, type)
        {

        }

        public StringTypeTerminal(string name) : this(name, new StringType()) { }

        public override DataTypeTerminal<StringType> CreateCustom()
        {
            return new StringTypeTerminal("CustomString", new StringType());
        }

        public override Irony.Parsing.BnfExpression CreateRule(AnyTextGrammar grammar)
        {
            StringLiteral singleQuoted = new StringLiteral("SingleQuotedString", "'", StringOptions.AllowsAllEscapes);
            singleQuoted.AddPrefix("@", StringOptions.NoEscapes | StringOptions.AllowsLineBreak | StringOptions.AllowsDoubledQuote);
            StringLiteral doubleQuoted = new StringLiteral("DoubleQuotedString", "\"", StringOptions.AllowsAllEscapes);
            doubleQuoted.AddPrefix("@", StringOptions.NoEscapes | StringOptions.AllowsLineBreak | StringOptions.AllowsDoubledQuote);

            return singleQuoted | doubleQuoted;
        }
    }
}
